//
//  ZNLetterListViewController.m
//  u76ho
//
//  Created by m-air-01 on 16/1/25.
//  Copyright © 2016年 LV. All rights reserved.
//

#import "ZNLetterListViewController.h"
#import "MineFirCell.h"
#import "ZNLetterViewController.h"
@interface ZNLetterListViewController ()
<UITableViewDataSource,UITableViewDelegate>
{
    UITableView * _tableView;
    NSMutableArray * dataSource;
}
@end

@implementation ZNLetterListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self main];
    
    self.navigationItem.title = @"站内信";
   // [self addBackItem];
    //[self addNavgationBar];
    // Do any additional setup after loading the view.
}
-(void)main
{
    dataSource = [[NSMutableArray alloc]init];
    
    self.view.backgroundColor = [UIColor whiteColor];
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 63, SCREEN_WIDTH, SCREEN_HEIGHT-63) style:UITableViewStyleGrouped];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    [_tableView registerNib:[UINib nibWithNibName:@"MineFirCell" bundle:nil] forCellReuseIdentifier:@"MineFirCell"];
    [self.view addSubview:_tableView];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self requestData];
}
-(void)requestData
{
    [U76HONet zhanneiLetterListWithaction:@"" code:[Singleton share].code andDataBlock:^(NSArray *arr) {
        NSLog(@"站内信列表数据获取成功列");
        if (arr.count == 0) {
            [self nosearch];
        }
        else
        {
            if (dataSource.count != 0) {
                [dataSource removeAllObjects];
            }
            [dataSource addObjectsFromArray:arr];
            [_tableView reloadData];
        }
    }];
}
-(void)nosearch
{
    UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT-64)];
    view.backgroundColor = UIColorFromRGB(0xf1f3f2);
    view.tag = 504;
    
    UIImageView * imgV = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2-98/2,SIZETO6H(120), 98, 100)];
    imgV.image = [UIImage imageNamed:@"苦脸"];
    [view addSubview:imgV];
    
    UILabel * tipLab = [[UILabel alloc]initWithFrame:CGRectMake(0, imgV.bottom+SIZETO6H(20), SCREEN_WIDTH, 20)];
    tipLab.text = @"暂时没有符合条件的内容";
    tipLab.textAlignment = NSTextAlignmentCenter;
    tipLab.font = [UIFont systemFontOfSize:14];
    tipLab.textColor = UIColorFromRGB(0x333944);
    [view addSubview:tipLab];
    [self.view addSubview:view];
}

#pragma mark - _tableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return dataSource.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MineFirCell * cell = [tableView dequeueReusableCellWithIdentifier:@"MineFirCell"];
    ZNletterModel * model = dataSource[indexPath.row];
    cell.contentLab.text = model.title;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 1;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ZNLetterViewController * zhanneiLVC = [[ZNLetterViewController alloc]init];
    ZNletterModel * model = dataSource[indexPath.row];
    zhanneiLVC.ids = model.ids;
    [self.navigationController pushViewController:zhanneiLVC animated:YES];
}
#pragma  mark - 返回按钮图标
-(void)addBackItem{
    UIButton * backItem = [UIButton buttonWithType:UIButtonTypeCustom];
    backItem.frame = CGRectMake(0, 0, 9, 17);
    [backItem setImage:[UIImage imageNamed:@"返回图标"] forState:UIControlStateNormal];
    [backItem addTarget:self action:@selector(backItem:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backItem];
}
-(void)backItem:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
